//
//  XJYLoginViewController.m
//  ShopMall
//
//  Created by XJY on 17/1/19.
//  Copyright © 2017年 XinJinYing. All rights reserved.
//

#import "XJYLoginViewController.h"
#import "XJYLoginView.h"
#import "XJYThirdLoginView.h"
@interface XJYLoginViewController ()

@property (nonatomic, strong) XJYLoginView *loginView;

@property (nonatomic, strong) XJYThirdLoginView *thirdLoginView;

@end

@implementation XJYLoginViewController

#pragma mark - 懒加载
- (XJYLoginView *)loginView
{
    if (!_loginView) {
        _loginView = [[XJYLoginView alloc] init];
        _loginView.loginBlock = ^(NSDictionary *dic) {
            [self loginMethod:dic];
        };
    }
    return _loginView;
}

- (XJYThirdLoginView *)thirdLoginView
{
    if (!_thirdLoginView) {
        _thirdLoginView = [[XJYThirdLoginView alloc] init];
    }
    return _thirdLoginView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"登录";
    self.edgesForExtendedLayout = 0;
    [self.view addSubview:self.loginView];
    [self.view addSubview:self.thirdLoginView];
    [self setupLayout];
}

- (void)setupLayout
{
    __weak typeof(self) weakSelf = self;
    [_loginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(weakSelf.view);
        make.height.equalTo(@230);
    }];
    
    [_thirdLoginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.loginView.mas_bottom);
        make.left.right.equalTo(weakSelf.view);
        make.height.equalTo(@90);
    }];
}

#pragma mark - 登录方法请求接口
- (void)loginMethod:(NSDictionary *)dic
{
    [self showTostMessage:@"登录成功"];
    [[NSUserDefaults standardUserDefaults] setObject:@1 forKey:@"ISLOGIN"];
    [self performSelector:@selector(popMyViewController) withObject:nil afterDelay:1.0];
    /*
    [self getWithPath:@"appMember/appLogin.do" params:dic success:^(id json) {
        XJYLog(@"responseObject: %@", json);
        if ([json[@"ErrorMessage"] isEqualToString:@"登陆成功"]) {
            [self showTostMessage:@"登录成功"];
            [[NSUserDefaults standardUserDefaults] setObject:json forKey:@"ISLOGIN"];
            [self performSelector:@selector(popMyViewController) withObject:nil afterDelay:1.0];
        }else if ([json[@"ErrorMessage"] isEqualToString:@"密码错误"]){
            [self showTostMessage:@"密码错误"];
        }else if ([json[@"ErrorMessage"] isEqualToString:@"用户不存在"]){
            [self showTostMessage:@"用户不存在"];
        }else{
            [self showTostMessage:@"登录失败"];
        }

    } failure:^(NSError *error) {
        XJYLog(@"error : %@",error);
    }];
     */
}

- (void)popMyViewController
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
